package com.mybatis;

import com.mybatis.mapper.UserMapper;
import com.mybatis.pojo.User;
import com.mybatis.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Part11_Insert {
    public static void main(String[] args) {
        SqlSession sqlSession = MyBatisUtils.getSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        List<Integer> sids = Arrays.asList(3, 4);
        List<User> users = userMapper.findUsersByIds(sids);
        System.out.println("通过学号查询的结果：");
        // 打印查询结果
        for (User user : users) {
            System.out.println(user);
        }
        // 通过姓名查询
        String name = "张三";
        List<User> usersByName = userMapper.findUsersByName(name);
        // 打印通过姓名查询的结果
        System.out.println("通过姓名查询的结果：");
        for (User user : usersByName) {
            System.out.println(user);
        }

        // 通过年龄查询
        int age = 24;
        List<User> usersByAge = userMapper.findUsersByAge(age);
        // 打印通过年龄查询的结果
        System.out.println("通过年龄查询的结果：");
        for (User user : usersByAge) {
            System.out.println(user);
        }

        // 年龄与姓名组合查询
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("name", name);
        paramMap.put("age", age);
        List<User> usersByCombination = userMapper.findUsersByCombination(paramMap);
        // 打印年龄与姓名组合查询的结果
        System.out.println("年龄与姓名组合查询的结果：");
        for (User user : usersByCombination) {
            System.out.println(user);
        }
        sqlSession.close();
    }
}